package com.tomato.dto;

import com.tomato.entity.TodoRecord;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@Schema(description = "待办记录同步传输对象")
public class TodoRecordSyncDTO {

    @Schema(description = "客户端本地创建时间", required = true, example = "2023-08-01T10:00:00")
    private LocalDateTime clientCreatedAt;

    @Schema(description = "本次开始时间", required = true, example = "2023-08-01T10:00:00")
    private LocalDateTime startTime;

    @Schema(description = "本次结束时间", example = "2023-08-01T10:25:00")
    private LocalDateTime endTime;

    @Schema(description = "是否已完成", example = "true", defaultValue = "false")
    private Boolean finished = false;

    @Schema(description = "实际总专注秒数", example = "3000", defaultValue = "0")
    private Integer actualFocusSeconds = 1;

    @Schema(description = "实际休息秒数", example = "300", defaultValue = "0")
    private Integer actualRestSeconds = 0;

    public TodoRecord toEntity(Long userId) {
        TodoRecord record = new TodoRecord();
        record.setUserId(userId); // 直接使用服务端验证后的userId
        record.setStartTime(this.startTime);
        record.setEndTime(this.endTime);
        record.setFinished(this.finished);
        record.setActualFocusSeconds(this.actualFocusSeconds);
        record.setActualRestSeconds(this.actualRestSeconds);
        record.setCreatedAt(this.clientCreatedAt != null ?
                this.clientCreatedAt : LocalDateTime.now());
        return record;
    }
}